package com.dongdongshop.service.impl;

import com.dongdongshop.domain.model.TbAreas;
import com.dongdongshop.domain.model.TbAreasExample;
import com.dongdongshop.domain.model.TbCities;
import com.dongdongshop.domain.model.TbCitiesExample;
import com.dongdongshop.domain.vo.AreasVO;
import com.dongdongshop.domain.vo.CitiesVO;
import com.dongdongshop.mapper.TbCitiesMapper;
import com.dongdongshop.service.CitiesService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CitiesServiceImpl implements CitiesService {

    @Autowired
    private TbCitiesMapper citiesMapper;

    @Override
    public List<CitiesVO> getCitiesByProvinceId(String provinceId) {
        TbCitiesExample example = new TbCitiesExample();
        example.createCriteria().andProvinceidEqualTo(provinceId);
        List<TbCities> tbCitiesList = citiesMapper.selectByExample(example);
        return tbCitiesList.stream().map(tbCities -> {
            CitiesVO vo = new CitiesVO();
            BeanUtils.copyProperties(tbCities,vo);
            return vo;
        }).collect(Collectors.toList());
    }
}
